Introduction

Previously, you learned about the importance of creating an onboarding flow for mobile apps in order to get new users acquainted with the app and its features as quickly and efficiently as possible. In this exercise, you’ll put those ideas into practice for a page built with SwiftUI.

Scenario

Before users start ordering food through the Little Lemon app, it’s important that they know how to make use of the app and understand what features it has. While you won’t create a full onboarding flow here, you’ll get one started by creating a registration page that prompts the user to enter their name and password.

Instructions

Before you begin, make sure you have the latest version of XCode. Use the project you set up in the previous exercise: Module 1 Lesson 2 item 06 - Setting up a SwiftUI project

The registration page should have the following elements:

Follow the steps below to implement the registration page.

Step 1: Create a new SwiftUI file for onboarding

You should now have a file in your project file tree named Onboarding.swift and it should load as a first screen when you run your application.

Tip: Notice that the latest XCode does not display file extensions by default so you will likely only see the file named Onboarding without the extension .swift in the project files tree.

To recap how to create new files and navigate Xcode, you can review the following resources:

Step 2: Add a vertical stack to your onboarding page

Open the newly created Onboarding file. You will see some default view code generated for you that outputs “ Hello, World! ” using a Text element.

Modify it as follows:

Tip: If you are having trouble implementing any of the previous steps, review the following resources:

Step 3: Add three text fields to input user information

Add three text fields inside the VStack to input the first name , last name and email information of the user:

Tip: Remember, when passing the state variable to the TextField , use the $ sign before the name of the variable. If you need any help with the steps above, refer to the following resource:

Step 4: Add a button to complete the registration

If you run the project now you should see a button appear below the text fields.

Tip: If you need any help with the steps above, refer to the following resource:

To style your views in a more advanced way you can refer to the contents covered in the Create the User Interface with SwiftUI course, as well as view the following documentation:

Conclusion

In this exercise, you found out how to create a registration page that asked the user to enter their name and password. This is useful as the starting page for a more fully-developed onboarding flow.